package com.example.systemserver.Controller;

import cn.hutool.jwt.JWTUtil;
import com.example.systemserver.Bean.RequestBean;
import com.example.systemserver.Bean.ResultBean;
import com.example.systemserver.Bean.StudentBean;
import com.example.systemserver.Service.StudentService;
import com.github.pagehelper.PageInfo;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

// 这个类中的方法都是用于接收参数和返回数据给客户端的

@Slf4j
@RestController
@RequestMapping("/student")
public class StudentController {
    // title=张三&age=18&gender=男&address=上海  param格式
    // {title:‘张三’,age:18,gender:'男',address:'上海'} JSON格式

    @Autowired
    private StudentService studentService;

    @RequestMapping("/save") // student/save
    public ResultBean save(@RequestBody StudentBean studentBean){
        log.info("/student/save,学员信息保存，请求参数:{}", studentBean);
        studentService.save(studentBean);
        log.info("/student/save,学员信息保存，返回值:null");
        return new ResultBean(200, "保存成功", null);
    }

    @RequestMapping("/list")
    public ResultBean list(@RequestBody RequestBean requestBean){
        log.info("/student/list,查询列表，请求参数:{}", requestBean);
        PageInfo<StudentBean> pageInfo = studentService.list(requestBean);
        log.info("/student/list,查询列表，返回值:{}", pageInfo);
        return new ResultBean(200,"查询成功",pageInfo);
    }
    @RequestMapping("/remove")
    public ResultBean remove(@RequestBody StudentBean studentBean){
        boolean flg = studentService.remove(studentBean);
        if (flg){
            return new ResultBean(200,"删除成功",null);
        }else{
            return new ResultBean(500,"删除失败",null);
        }
    }

    @RequestMapping("/info")
    public ResultBean info(@RequestBody StudentBean studentBean){
        StudentBean info = studentService.info(studentBean);
        return new ResultBean(200,"查询成功",info);
    }
}